package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManagerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ author     ：廖传港
 * @ date       ：Created in 2020/12/21 19:37
 * @ description：
 * @ modified By：
 * @ ersion:
 */
@Api(description = "分类与平台属性接口")
@RequestMapping("/admin/product")
@RestController
public class ManagerController {

    @Autowired
    private ManagerService managerService;

    @ApiOperation("获取一级分类")
    @GetMapping("getCategory1")
    public Result<List<BaseCategory1>> getCategory1() {
        List<BaseCategory1> category1List = managerService.getCategory1();
        return Result.ok(category1List);
    }

    @ApiOperation("获取二级分类")
    @GetMapping("getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(@PathVariable Long category1Id) {
        List<BaseCategory2> category2List = managerService.getCategory2(category1Id);
        return Result.ok(category2List);
    }
    @ApiOperation("获取三级分类")
    @GetMapping("getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory3(@PathVariable Long category2Id) {
        List<BaseCategory3> category3List = managerService.getCategory3(category2Id);
        return Result.ok(category3List);
    }

    @ApiOperation("根据分类id获取平台属性")
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> attrInfoList(@PathVariable Long category1Id,
                                                   @PathVariable Long category2Id,
                                                   @PathVariable Long category3Id) {
        List<BaseAttrInfo> attrInfoListList = managerService.attrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(attrInfoListList);
    }


    @ApiOperation("添加/修改平台属性")
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo) {
        managerService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    @ApiOperation("根据平台属性ID获取平台属性")
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId) {
        BaseAttrInfo baseAttrInfo = managerService.getAttrValueList(attrId);
        return Result.ok(baseAttrInfo);
    }

    @ApiOperation("获取品牌分页列表")
    @GetMapping("baseTrademark/{page}/{limit}")
    public Result baseTrademark(@PathVariable Integer page,
                                @PathVariable Integer limit) {
        IPage<BaseTrademark> baseTrademarkList = managerService.baseTrademark(page,limit);
        return Result.ok(baseTrademarkList);
    }


    @ApiOperation("修改品牌之回显操作")
    @GetMapping("baseTrademark/get/{id}")
    public Result getbaseTrademark(@PathVariable Integer id) {
        BaseTrademark baseTrademark = managerService.getbaseTrademark(id);
        return Result.ok(baseTrademark);
    }
    @ApiOperation("修改品牌之修改操作")
    @PutMapping("baseTrademark/update")
    public Result update(@RequestBody BaseTrademark trademark) {
        managerService.update(trademark);
        return Result.ok();
    }

    @ApiOperation("保存品牌数据")
    @PostMapping("baseTrademark/save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark trademark) {
        managerService.save(trademark);
        return Result.ok();
    }

    @ApiOperation("删除品牌数据")
    @DeleteMapping("baseTrademark/remove/{id}")
    public Result removeBaseTrademark(@PathVariable Long id) {
        managerService.removeBaseTrademark(id);
        return Result.ok();
    }






    //第二页面


    @ApiOperation("商品属性SPU管理之总体数据查询")
    @GetMapping("{page}/{limit}")
    public Result spuList(@PathVariable Integer page,
                         @PathVariable Integer limit,
                         Long category3Id) {
        IPage<SpuInfo> skuInfos = managerService.spuList(page, limit, category3Id);
        return Result.ok(skuInfos);
    }

    @ApiOperation("查询销售属性")
    @GetMapping("baseSaleAttrList")
    public Result baseSaleAttrList() {
        List<BaseSaleAttr> baseSaleAttrList = managerService.baseSaleAttrList();
        return Result.ok(baseSaleAttrList);
    }

    @ApiOperation("获取品牌属性")
    @GetMapping("baseTrademark/getTrademarkList")
    public Result getTrademarkList() {
        List<BaseTrademark> baseTrademarkList = managerService.getTrademarkList();
        return Result.ok(baseTrademarkList);
    }

    @ApiOperation("添加spu")
    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo) {
        managerService.saveSpuInfo(spuInfo);
        return Result.ok();
    }


    @ApiOperation("根据spuId获取图片列表")
    @GetMapping("spuImageList/{spuId}")
    public Result spuImageList(@PathVariable Long spuId) {

        List<SpuImage> spuImages = managerService.spuImageList(spuId);
        return Result.ok(spuImages);
    }

    @ApiOperation("根据spuId获取销售属性")
    @GetMapping("spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable Long spuId) {

        List<SpuSaleAttr> spuSaleAttrList = managerService.spuSaleAttrList(spuId);
        return Result.ok(spuSaleAttrList);
    }


    @ApiOperation("添加sKu")
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo) {
        managerService.saveSkuInfo(skuInfo);
        return Result.ok();
    }

    @ApiOperation("获取sku分页列表")
    @GetMapping("list/{page}/{limit}")
    public Result list(@PathVariable Integer page,
                       @PathVariable Integer limit) {

        IPage<SkuInfo> infoIPage = managerService.list(page,limit);
        return Result.ok(infoIPage);
    }

    @ApiOperation("上架")
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId) {
        managerService.onSale(skuId);
        return Result.ok();
    }

    @ApiOperation("下架")
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId) {
        managerService.cancelSale(skuId);
        return Result.ok();
    }

}
